//
//  LoanProgressView.swift
//  EasyDana
//
//  Created by mac on 2024/10/12.
//

import UIKit
import RxSwift
import RxCocoa
class LoanProgressView: UIView {

    let bag = DisposeBag()
    
    let step = BehaviorRelay(value: 0)
    
    required init?(coder: NSCoder) {
        super.init(coder: coder)
        self.configView()
    }
    
    private func configView() {
        let firstStepView = UIImageView(image: UIImage(named: "loan_process_done"))
        self.addSubview(firstStepView)
        firstStepView.snp.makeConstraints { make in
            make.centerX.equalToSuperview()
            make.top.equalToSuperview()
        }
        let doneImage = UIImage(named: "loan_process_doneprocess")
        let notDoneImage = UIImage(named: "loan_process_notdoneprogress")
        let secondStepView = UIImageView(image: UIImage(named: "load_progress_notdoneprocess"))
        self.addSubview(secondStepView)
        secondStepView.snp.makeConstraints { make in
            make.centerX.equalToSuperview()
            make.top.equalTo(firstStepView.snp.bottom).offset(8)
        }
        self.step
            .map { stp in
                return stp >= 1 ? doneImage : notDoneImage
            }
            .bind(to: secondStepView.rx.image)
            .disposed(by: self.bag)
        let thirdStepView = UIImageView(image: UIImage(named: "load_progress_notdoneprocess"))
        self.addSubview(thirdStepView)
        thirdStepView.snp.makeConstraints { make in
            make.centerX.equalToSuperview()
            make.top.equalTo(secondStepView.snp.bottom).offset(8)
        }
        self.step
            .map { stp in
                return stp >= 2 ? doneImage : notDoneImage
            }
            .bind(to: thirdStepView.rx.image)
            .disposed(by: self.bag)
        let forthStepView = UIImageView(image: UIImage(named: "load_progress_notdoneprocess"))
        self.addSubview(forthStepView)
        forthStepView.snp.makeConstraints { make in
            make.centerX.equalToSuperview()
            make.top.equalTo(thirdStepView.snp.bottom).offset(8)
        }
        self.step
            .map { stp in
                return stp >= 3 ? doneImage : notDoneImage
            }
            .bind(to: forthStepView.rx.image)
            .disposed(by: self.bag)
        let fifthStepView = UIImageView(image: UIImage(named: "load_progress_notdoneprocess"))
        self.addSubview(fifthStepView)
        fifthStepView.snp.makeConstraints { make in
            make.centerX.equalToSuperview()
            make.top.equalTo(forthStepView.snp.bottom).offset(8)
        }
        self.step
            .map { stp in
                return stp >= 4 ? doneImage : notDoneImage
            }
            .bind(to: fifthStepView.rx.image)
            .disposed(by: self.bag)
    }
    
    /*
    // Only override draw() if you perform custom drawing.
    // An empty implementation adversely affects performance during animation.
    override func draw(_ rect: CGRect) {
        // Drawing code
    }
    */

}
